package cn.fl.mcr.service.impl;

import cmm.comm.facade.framework.api.ISysDictionaryApiService;
import cmm.mid.core.framework.page.KeyValueVO;
import cn.cmm.base.framework.exception.BaseException;
import cn.cmm.base.framework.utils.CollectionUtils;
import cn.cmm.base.framework.utils.StringUtils;
import cn.fl.framework.base.context.CurrentThreadContext;
import cn.fl.mcr.service.IMcrBillDService;
import cn.fl.mcr.transform.McrBillDVOTransform;
import cn.fl.mcr.vo.McrBillDVO;
import cn.lionbridgecapital.loan.model.condition.McrBillDQC;
import cn.lionbridgecapital.loan.model.dto.McrBillDDTO;
import cn.lionbridgecapital.loan.service.api.IMcrBillDApiService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @Description: 小贷账单明细表 客户端服务层接口实现
 * 业务层方法名称前缀：
 * 新增：add*
 * 删除：remove*
 * 修改：modify*
 * 批量：batch*
 * 查询对象：select* get*
 * 查询集合：search*
 */
@Service
public class McrBillDServiceImpl implements IMcrBillDService {

	/**
     * 日志
     */
    @SuppressWarnings("unused")
    private static final Logger logger = LoggerFactory.getLogger(McrBillDServiceImpl.class);
	
	/**
	 * 小贷账单明细表 暴露服务
	 */
	@Autowired
	private IMcrBillDApiService publicMcrBillDApiService;
	@Autowired
	private cn.fl.mcr.api.IMcrBillDApiService mcrBillDApiService;
	/**
     * 数据字典服务
     */
    @Autowired
    private ISysDictionaryApiService sysDictionaryApiService;

	@Override
	public McrBillDVO selectById(Long id) throws BaseException{
		if(StringUtils.isEmpty(id)) return null;
		McrBillDDTO dto = this.publicMcrBillDApiService.selectMcrBillDById(id);
		return McrBillDVOTransform.toVO(dto);
	}

	@Override
	public List<McrBillDVO> searchList(McrBillDQC condition) throws BaseException{
		if(null == condition) condition=new McrBillDQC();
		List<McrBillDVO> voList=McrBillDVOTransform.toVOList(this.publicMcrBillDApiService.searchMcrBillDList(condition));
		this.setDictData(voList);
		return voList;
	}
	
    /**
     * 添加数据字典名称
     * @param voList
     */
	public void setDictData(List<McrBillDVO> voList){
		if(CollectionUtils.isEmpty(voList)) return;
		/*Map<String, String> _CdMap = this.sysDictionaryApiService.searchGroupToMap(sysCd, orgCd, McrBillDConstant.CODE_CD);
		for(McrBillDVO vo:voList){
			if (_CdMap != null && _CdMap.containsKey(vo.getCd())) {
            	vo.setCdNm(_CdMap.get(vo.getCd()));
        	}	
		}*/
	}
	
	/**
     * 查询数据字典
     * @param groupCd 组代码
     * @return List<KeyValueVO>
     */
    public List<KeyValueVO> searchCdList(String groupCd){
        return this.sysDictionaryApiService.getKvList(groupCd, CurrentThreadContext.getCurrentSysCd(), CurrentThreadContext.getCurrentOrgCd());
    }

	@Override
	public List<McrBillDVO> searchList(cn.fl.mcr.condition.McrBillDQC condition) throws BaseException{
		if(null == condition) condition=new cn.fl.mcr.condition.McrBillDQC();
		List<cn.fl.mcr.dto.McrBillDDTO> list = this.mcrBillDApiService.searchMcrBillDList(condition);
		List<McrBillDVO> voList=McrBillDVOTransform.toVoList(list);
		this.setDictData(voList);
		return voList;
	}
}
